﻿--[[
	This file is part of FlexBar3.

	FlexBar3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	FlexBar3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with FlexBar3.  If not, see <http://www.gnu.org/licenses/>.
]]
-- Local upvalues
local FlexBar3 = FlexBar3;
local CharacterID = ("%s - %s"):format(GetRealmName(), UnitName("player"));

function FlexBar3:InitializeDB()
	if(not FlexBar3_DB) then FlexBar3_DB = { CurrentProfile = {}, Profiles = {}}; end
	if(not FlexBar3_DB.CurrentProfile[CharacterID]) then
		FlexBar3_DB.CurrentProfile[CharacterID] = CharacterID;
	end
	local CurrentProfile = FlexBar3_DB.CurrentProfile[CharacterID];
	if(not FlexBar3_DB.Profiles[CurrentProfile]) then
		FlexBar3_DB.Profiles[CurrentProfile] =	{ Enabled = true };
	end
	self.DB = FlexBar3_DB.Profiles[CurrentProfile];
end

function FlexBar3:SetProfile(NewProfile)
	local DB = FlexBar3_DB;
	FlexBar3:Disable();
	DB.CurrentProfile[CharacterID] = NewProfile;
	if(not DB.Profiles[NewProfile]) then
		DB.Profiles[NewProfile] = {};
	end
	self.DB = FlexBar3_DB.Profiles[NewProfile];
	FlexBar3:Enable();
end
